package com.luania.todolist2.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.luania.todolist2.R;
import com.luania.todolist2.Model.ImageModel;

import java.util.ArrayList;
import java.util.List;

public class IconAdapter extends BaseAdapter {
    List<ImageModel> images = new ArrayList<>();
    Context context;

    public IconAdapter(List<ImageModel> images, Context context) {
        this.images = images;
        this.context = context;
    }

    public int getCount() {
        return images.size();
    }


    @Override
    public Object getItem(int position) {
        return images.get(position);
    }


    @Override
    public long getItemId(int position) {
        //...
        return images.get(position).getImageId();
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d("hehe", "getView");

        //获取布局填充器
        LayoutInflater inflater = LayoutInflater.from(context);
        //使用布局填充器将布局填充到view中（解析xml）
        View view = inflater.inflate(R.layout.item_icon, parent, false);

        TextView tv_icon = (TextView) view.findViewById(R.id.tv_icon);
        tv_icon.setText(images.get(position).getImageName());

        ImageView iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
        iv_icon.setImageResource(images.get(position).getImageId());
        return view;
    }
}

